package com.gitee.feizns.web.utils;

import org.springframework.context.ApplicationContext;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * @author feizns
 * @since 2019/7/13
 */
public class AppUtils {

    private static ApplicationContext APPLICATION_CONTEXT;

    public AppUtils(ApplicationContext act) {
        APPLICATION_CONTEXT = act;
    }

    public static ApplicationContext getApp() {
        return APPLICATION_CONTEXT;
    }

    public static <T> Collection<T> getBeansOfType(Class<T> type) {
        Map<String, T> ret = APPLICATION_CONTEXT.getBeansOfType(type);
        return ret != null ? ret.values() : Collections.emptyList();
    }

    public static <T> T getBean(Class<T> type) {
        return APPLICATION_CONTEXT.getBean(type);
    }

}
